package jdbc_test.datasource;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class DBUtils_USE {

    public static void main(String[] args) throws SQLException {
        DBUtils_USE dbUtils_use = new DBUtils_USE();
        dbUtils_use.testQueryMany();
    }
    public void testQueryMany() throws SQLException {

//        1.得到连接（Druid）
        Connection connection = JDBCUtilsByDruid.getConnection();
//        2.导入jar包
//        3.创建QueryRunner
        QueryRunner queryRunner = new QueryRunner();

//        4.执行相关方法，返回ArrayList结果集
        String sql = "select * from table1 where id>=?";
        List<Table> list = queryRunner.query(connection,sql,new BeanHandler<>(Table.class), 1);
        System.out.println("输出集合的信息");
        for (Table table:list){
            System.out.println(table);
        }

    }
}
